FROM eclipse-temurin:11-jdk-alpine as builder
WORKDIR app
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
RUN java -Djarmode=layertools -jar app.jar extract

FROM eclipse-temurin:11-jdk-alpine
MAINTAINER SDT_IT
LABEL project=openai
ENV TZ Asia/Shanghai
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \
    && apk -U upgrade && apk add tzdata curl sudo
RUN cp /usr/share/zoneinfo/${TZ} /etc/localtime && echo ${TZ} > /etc/timezone
RUN addgroup -S spring && adduser -S spring -G spring
RUN mkdir -p /etc/sudoers.d \
    && echo "spring ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/spring \
    && chmod 0440 /etc/sudoers.d/spring

RUN mkdir -p /var/log/openai && chown spring:spring -R /var/log/openai
USER spring:spring
WORKDIR app
COPY --from=builder app/dependencies/ ./
COPY --from=builder app/spring-boot-loader/ ./
COPY --from=builder app/snapshot-dependencies/ ./
COPY --from=builder app/application/ ./
RUN sudo chown spring:spring -R /app
#ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]
ENTRYPOINT  ["sh","-c","java  $JAVA_OPTS org.springframework.boot.loader.JarLauncher $PARAMS"]
